Completed
Push — master ( 40c2b4...09bd06 )
by Justin
01:29
created

NamePart.setQualifiers   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 3
loc 3
rs 10
1 View Code Duplication
var ExtensibleData = require('./ExtensibleData'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    Qualifier = require('./Qualifier'),
3
    utils = require('./utils');
4
5
/**
6
 * A part of a name.
7
 * 
8
 * @constructor
9
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
10
 */
11
var NamePart = function(json){
12
  
13
  // Protect against forgetting the new keyword when calling the constructor
14
  if(!(this instanceof NamePart)){
15
    return new NamePart(json);
16
  }
17
  
18
  // If the given object is already an instance then just return it. DON'T copy it.
19
  if(NamePart.isInstance(json)){
20
    return json;
21
  }
22
  
23
  ExtensibleData.call(this, json);
24
  
25
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
26
    this.setValue(json.value);
27
    this.setType(json.type);
28
    this.setQualifiers(json.qualifiers);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  }
30
};
31
32
NamePart.prototype = Object.create(ExtensibleData.prototype);
33
34
NamePart._gedxClass = NamePart.prototype._gedxClass = 'GedcomX.NamePart';
35
36
/**
37
 * Check whether the given object is an instance of this class.
38
 * 
39
 * @param {Object} obj
40
 * @returns {Boolean}
41
 */
42
NamePart.isInstance = function(obj){
43
  return utils.isInstance(obj, this._gedxClass);
44
};
45
46
/**
47
 * Get the type
48
 * 
49
 * @returns {String} type
50
 */
51
NamePart.prototype.getType = function(){
52
  return this.type;
53
};
54
55
/**
56
 * Set the type
57
 * 
58
 * @param {String} type
59
 * @returns {NamePart} This instance
60
 */
61
NamePart.prototype.setType = function(type){
62
  this.type = type;
63
  return this;
64
};
65
66
/**
67
 * Get the value
68
 * 
69
 * @returns {String}
70
 */
71
NamePart.prototype.getValue = function(){
72
  return this.value;
73
};
74
75
/**
76
 * Set the value
77
 * 
78
 * @param {String} value
79
 * @returns {NamePart} This instance
80
 */
81
NamePart.prototype.setValue = function(value){
82
  this.value = value;
83
  return this;
84
};
85
86
/**
87
 * Get qualifiers
88
 * 
89
 * @return {Qualifer[]}
90
 */
91
NamePart.prototype.getQualifiers = function(){
92
  return this.qualifiers || [];
93
};
94
95
/**
96
 * Set the qualifiers
97
 * 
98
 * @param {Qualifer[]|Object[]} qualifiers
99
 * @returns {NamePart} This instance
100
 */
101
NamePart.prototype.setQualifiers = function(qualifiers){
102
  return this._setArray(qualifiers, 'qualifiers', 'addQualifier');
103
};
104
105
/**
106
 * Add a qualifier
107
 * 
108
 * @param {Qualifier|Object} qualifier
109
 * @returns {NamePart} This instance
110
 */
111
NamePart.prototype.addQualifier = function(qualifier){
112
  return this._arrayPush(qualifier, 'qualifiers', Qualifier);
113
};
114
115
/**
116
 * Export the object as JSON
117
 * 
118
 * @return {Object} JSON object
119
 */
120
NamePart.prototype.toJSON = function(){
121
  return this._toJSON(ExtensibleData, [
122
    'type',
123
    'value',
124
    'qualifiers'
125
  ]);
126
};
127
128
module.exports = NamePart;